﻿Public Class FrmUpLoadPrg
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As IntPtr, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
    Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr

    Public ProgramPath As String = My.Application.Info.DirectoryPath & "\tool"
    Private Sub FrmUpLoadPrg_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ComboBox1.Text = ""
        ComboBox1.Items.Clear()
        GetDirectFiles(ProgramPath)
    End Sub
    Private Sub GetDirectFiles(ByVal s As String)
        '找出位于 s 根目录下的所有文件
        Try
            Dim i As Integer
            Dim t As Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles(s), k As String, name() As String
            ' Me.Text = s
            Dim f() As String
            For Each k In My.Computer.FileSystem.GetDirectories(s)
                ReDim Preserve f(i)
                f(i) = k
                If 1 Then
                    Dim myFileInfo As New IO.FileInfo(f(i))
                    name = Split(f(i), "\")
                    ComboBox1.Items.Add(name(UBound(name)))
                End If
                i += 1
            Next
        Catch
        End Try
    End Sub

    '    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    '        Try
    '            Dim Rarexe As String 'WINRAR执行文件的位置   
    '            Dim Source As String ' 压缩前的原始文件   
    '            Dim Target As String ' 压缩后的目标文件   
    '            Dim FileString As String 'Shell指令中的字符串   
    '            Dim Result As Long
    '            If ComboBox1.SelectedIndex = -1 Then
    '                MsgBox("未选择程序！或程序非下拉列表中选择！")
    '                GoTo d
    '            End If
    '            Rarexe = My.Application.Info.DirectoryPath & "\数据上传程序\WinRAR\WinRAR.exe"
    '            Source = """" & ProgramPath & "\" & ComboBox1.SelectedItem.ToString & """"

    '            Dim SN As String
    '            If MachineInfo1.Machine_MSN = "" Then
    '                SN = "null"
    '            Else
    '                SN = MachineInfo1.Machine_MSN
    '            End If
    '            'Target = SN & ComboBox1.SelectedItem.ToString & DateTime.Now.ToString("yyyyMMddhhddss") + ".rar"
    '            '财编+model+UCT.rar
    '            Target = SN & "_" & ComboBox1.SelectedItem.ToString & "_" & DateTime.Now.ToString("yyyyMMddhhddss") + ".rar"

    '            FileString = Rarexe & " a -ep1 " & Target & " " & Source
    '            Result = Shell(FileString, vbHide)
    '            System.Threading.Thread.Sleep(2500)

    '            UpLoadPIC(My.Application.Info.DirectoryPath & "\" & Target)
    '            MsgBox("操作完成")
    'd:

    '        Catch ex As Exception
    '            MsgBox("上传程序时报错：" & ex.Message.ToString)
    '        End Try
    '    End Sub
    Private Sub UpLoadPIC(ByVal picPath As String)
        Try
            Dim WM_SETFOCUS As IntPtr = &H7
            Dim WM_SETTEXT As IntPtr = &HC
            Dim lngCalculator As IntPtr = FindWindow(vbNullString, "数据上传")
            Dim Line As IntPtr = FindWindowEx(lngCalculator, 0, vbNullString, "MODEL")
            Dim j As Integer = SendMessage(Line, WM_SETTEXT, 0, picPath)
        Catch ex As Exception

        End Try
    End Sub
End Class